import 'package:audioplayers/audioplayers.dart';
import 'package:calendar_girl/utils/music-icon.dart';
import 'package:calendar_girl/views/play/model/MusicModel.dart';
import 'package:flutter/material.dart';
import 'package:weui/weui.dart';

TextStyle textStyle = new TextStyle(fontSize: 10,color: Color(0xffE9E9E9));

class PlayPanel extends StatelessWidget {
  PlayPanel({@required this.music, this.onPlayChange});
  final MusicModel music;
  final Function onPlayChange;
  final AudioPlayer audioPlayer = AudioPlayer(mode: PlayerMode.LOW_LATENCY);
  GlobalKey _slideKey = new GlobalKey();
  int _slideVal = 0;
  _playLocal() {
    audioPlayer.play(music.url, stayAwake: true);
  }
  @override
  Widget build(BuildContext context) {
    // _playLocal();
    return Column(
      children: <Widget>[
        Row(
          children: <Widget>[
            new Text(MusicModel.lengthToString(music.length*music.progress~/100), style: textStyle),
            new Expanded(
              child: new Container(
                padding: EdgeInsets.symmetric(vertical: 0, horizontal: 10),
                // child: GestureDetector(
                //   key: _slideKey,
                //   onTapDown: (details) {
                //     int slideVal = (details.localPosition.dx/_slideKey.currentContext.size.width*100).toInt();
                //     onPlayChange(MusicChangeType.progress, slideVal);
                //   },
                //   child: Container(
                //     padding: EdgeInsets.symmetric(vertical: 10),
                //     child: WeSlider(
                //       value: music.progress,
                //       buttonSize: 10,
                //       higColor: Colors.red,
                //       onChange: (val) {
                //         onPlayChange(MusicChangeType.progress, val);
                //       },
                //     ),
                //   ),
                // ),
                child: WeSlider(
                  value: music.progress,
                  buttonSize: 10,
                  higColor: Colors.red,
                  onChange: (val) {
                    onPlayChange(MusicChangeType.progress, val);
                  },
                ),
              ),
            ),
            new Text(MusicModel.lengthToString(music.length), style: textStyle),
          ],
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            new IconButton(icon: Icon(Icons.favorite_border, size: 20, color: Colors.white,)),
            new Container(
              padding: EdgeInsets.symmetric(horizontal: 10),
              child: new Row(
                children: <Widget>[
                  new IconButton(icon: Icon(MusicIcon.backward, size: 28, color: Colors.white,)),
                  new IconButton(icon: Icon(music.playing ?  MusicIcon.stop : MusicIcon.play, size: 36, color: Colors.white,), onPressed: () {
                    onPlayChange(MusicChangeType.playing, !music.playing);
                  },),
                  new IconButton(icon: Icon(MusicIcon.forward, size: 28, color: Colors.white,)),
                ],
              ),
            ),
            new IconButton(icon: Icon(MusicIcon.menu, size: 20, color: Colors.white,)),
          ],
        )
      ],
    );
  }
}